package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.dao.provider.OrganizationProvider;
import com.jinmdz.fmis.dao.admin.model.organization.OrganizationEditItem;
import com.jinmdz.fmis.dao.admin.model.organization.OrganizationListItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;

/**
 * 组织机构维护Dao
 *
 * @author LiCongLu
 * @date 2020-03-16 10:51
 */
public interface OrganizationDao {

    /**
     * 查询组织机构列表
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-03-16 10:51
     */
    @SelectProvider(type = OrganizationProvider.class, method = "listOrganizationList")
    ArrayList<OrganizationListItem> listOrganizationList();

    /**
     * 按照父主键查询组织机构列表
     *
     * @param parentId 父主键
     * @return
     * @author LiCongLu
     * @date 2020-03-16 11:06
     */
    @SelectProvider(type = OrganizationProvider.class, method = "listOrganizationListByParentId")
    ArrayList<OrganizationListItem> listOrganizationListByParentId(@Param("parentId") Integer parentId);

    /**
     * 按照父主键获取组织机构个数
     *
     * @param parentId 父主键
     * @return
     * @author LiCongLu
     * @date 2020-03-16 11:06
     */
    @Select(" select count(*) as organization_count from organization_institution where parent_id = #{parentId} and deleted = 0 ")
    @ResultType(Integer.class)
    Integer getOrganizationCountByParentId(@Param("parentId") Integer parentId);

    /**
     * 按照主键获取组织机构信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-16 10:51
     */
    @SelectProvider(type = OrganizationProvider.class, method = "getOrganizationEditById")
    OrganizationEditItem getOrganizationEditById(@Param("id") Integer id);

    /**
     * 按照组织机构编码查询非当前组织机构信息主键
     *
     * @param organizationId   当前组织机构主键
     * @param organizationCode 组织机构编码
     * @return
     * @author LiCongLu
     * @date 2020-03-16 10:51
     */
    @Select(" select id from organization_institution where id != IFNULL(#{organizationId},0) and organization_code = #{organizationCode} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getOrganizationIdByOrganizationCode(@Param("organizationId") Integer organizationId, @Param("organizationCode") String organizationCode);

    /**
     * 按照组织机构编码查询非当前组织机构信息主键
     *
     * @param organizationId   当前组织机构主键
     * @param organizationName 组织机构名称
     * @param parentId         父类主键
     * @return
     * @author LiCongLu
     * @date 2020-03-16 10:51
     */
    @Select(" select id from organization_institution where id != IFNULL(#{organizationId},0) and organization_name = #{organizationName} and parent_id = #{parentId} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getOrganizationIdByOrganizationName(@Param("organizationId") Integer organizationId, @Param("organizationName") String organizationName, @Param("parentId") Integer parentId);
}
